class shuzu {
    public static void main(String[] args) {
      int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
        
        int a=0;
        while (a<7){
            if(arr[a]>4)
                arr[a] = arr[a+1];
            a++;
        }
        arr[7] = 0;
       
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
        int b=7;
        while(b>0){
            if(arr[b]>4)
                arr[b]=arr[b-1];
            b--;
        }
        arr[4]=5;
        arr[7]=8;
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
    }
}
